<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px">
      <el-form-item label="小区" prop="areaName">
        <el-select v-model="queryParams.areaName":filter-method="filterMethod" placeholder="请输入小区" filterable allow-create
                   clearable size="small" @change="getGroup(queryParams.areaName)" default-first-option>
          <el-option v-for="(item, index) in areaIdOptions" :key="index" :label="item.areaName"
                     :value="item.areaName" :disabled="item.disabled" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="执行状态" prop="projectSts">
        <el-select v-model="queryParams.projectSts" clearable placeholder="请选择执行状态" size="small">
          <el-option
            v-for="dict in dict.type.REPAIR003"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="施工企业" prop="companyName">
        <el-select v-model="queryParams.companyName" size="small" filterable :filter-method="companyMethod"
                   :style="{width: '100%'}" clearable placeholder="请选择施工企业" default-first-option>
          <el-option v-for="(item, index) in companyOptions" :key="index" :disabled="item.disabled"
                     :label="item.companyName" :value="item.companyName"></el-option>
        </el-select>
<!--        <el-select v-model="form.companyName"  filterable allow-create
                   clearable size="small" placeholder="请选择施工企业" default-first-option >
          <el-option v-for="(item, index) in companyOptions" :key="index" :disabled="item.disabled"
                     :label="item.companyName" :value="item.companyName"></el-option>
        </el-select>-->
      </el-form-item>
      <el-form-item label="维修类型" prop="projectType">
        <el-select v-model="queryParams.projectType" clearable placeholder="维修类型" size="small">
          <el-option
            v-for="dict in dict.type.REPAIR002"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="维修内容" prop="infoName">
        <el-select size="small" v-model="queryParams.infoName" :style="{width: '100%'}" clearable placeholder="请选择维修内容">
          <el-option v-for="(item, index) in projectInfoOptions" :key="index" :disabled="item.disabled"
                     :label="item.infoName" :value="item.infoName"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工程编号" prop="projectId">
        <el-input
          v-model="queryParams.projectId"
          clearable
          placeholder="请输入工程编号"
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="执行日期">
        <el-date-picker
          v-model="dateRange"
          end-placeholder="结束日期"
          range-separator="-"
          size="small"
          start-placeholder="开始日期"
          style="width: 240px"
          type="daterange"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          icon="el-icon-plus"
          plain
          size="mini"
          type="primary"
          @click="handleAdd"
        >建项
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          :disabled="single"
          icon="el-icon-edit"
          plain
          size="mini"
          type="success"
          @click="handleProjectExecute"
        >执行
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          :disabled="multiple"
          icon="el-icon-delete"
          plain
          size="mini"
          type="danger"
          @click="handleDelete"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          :disabled="single"
          icon="el-icon-refund"
          plain
          size="mini"
          type="refund"
          @click="updateRefund"
        >撤销
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          icon="el-icon-download"
          plain
          size="mini"
          type="warning"
          @click="handleExport"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectList" @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column align="center" label="工程编号" prop="projectId" width="120"/>
      <el-table-column align="center" label="地址" prop="projectaddr" width="120"/>
      <el-table-column align="center" label="维修类型" prop="projectType" width="100">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.REPAIR002" :value="scope.row.projectType"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="工程名称" prop="projectName" width="200"/>
      <el-table-column :formatter="numberFormat" align="center" label="工程造价" prop="projectMoney" width="100"/>
      <el-table-column  :formatter="numberFormat" align="center" label="决算造价" prop="trueMoney" width="100"/>
      <el-table-column  :formatter="numberFormat" align="center" label="拨付金额" prop="payMoney" width="100"/>
      <el-table-column align="center" label="施工企业" prop="companyName"/>
      <el-table-column align="center" label="维修内容" prop="infoName"/>
      <el-table-column align="center" label="同意比例" prop="signSum"/>
      <el-table-column align="center" label="执行状态" prop="projectSts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.REPAIR003" :value="scope.row.projectSts"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="创建者" prop="creater" width="120"/>
      <el-table-column align="center" label="创建时间" prop="createDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="执行者" prop="executer" width="120"/>
      <el-table-column align="center" label="执行时间" prop="executeDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.executeDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="施工前公示开始日期" prop="publicityStart" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.publicityStart, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="施工前公示结束日期" prop="publicityEnd" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.publicityEnd, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="施工开始日期" prop="projectStart" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.projectStart, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="施工结束日期" prop="projectEnd" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.projectEnd, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="报价截至日期" prop="priceDate" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.priceDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="街道办事处负责人" prop="streeter"/>
      <el-table-column align="center" label="街道办事电话" prop="streetTel"/>
      <el-table-column align="center" label="社区负责人" prop="communityer"/>
      <el-table-column align="center" label="社区电话" prop="communityTel"/>
      <el-table-column align="center" label="业主委员会负责人" prop="committeer"/>
      <el-table-column align="center" label="业主委员会电话" prop="committeeTel"/>
      <el-table-column align="center" label="物业管理中心负责人" prop="homer"/>
      <el-table-column align="center" label="物业管理中心电话" prop="homeTel"/>
      <el-table-column align="center" label="备注" prop="remark"/>
      <el-table-column align="center" fixed="right" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button
            icon="el-icon-edit"
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            :style="{ display: scope.row.projectId=='合计'?'none':'' }"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="repairQuery(scope.row)"
            :style="{ display: scope.row.areaName=='合计'?'none':'' }"
          >查询明细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改维修项目对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="600px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="工程编号" prop="projectId">
              <el-input v-model="form.projectId" maxlength="30" placeholder="请输入工程编号"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="维修内容" prop="infoId">
              <el-select v-model="form.infoId" :style="{width: '100%'}" clearable placeholder="请输入维修内容">
                <el-option v-for="(item, index) in projectInfoOptions" :key="index" :disabled="item.disabled"
                           :label="item.infoName" :value="item.infoId">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工程名称" prop="projectName">
              <el-input v-model="form.projectName" maxlength="50" placeholder="请输入工程名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工程造价" prop="projectMoney">
              <el-input v-model="form.projectMoney" maxlength="50" placeholder="请输入工程造价"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="施工企业" prop="companyId">
              <el-select v-model="form.companyId":filter-method="companyMethod" placeholder="请选择施工企业" filterable allow-create
                         clearable default-first-option >
                <el-option v-for="(item, index) in companyOptions" :key="index" :disabled="item.disabled"
                           :label="item.companyName" :value="item.companyId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入内容" type="textarea"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="维修类型" prop="projectType">
              <el-radio-group v-model="form.projectType">
                <el-radio label="1">小区</el-radio>
                <el-radio label="2">楼宇</el-radio>
                <el-radio label="3">单元</el-radio>
                <el-radio label="4">自定义</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col
            v-if="form.projectType == '1'||form.projectType == '2'||form.projectType == '3'||form.projectType == '4'"
            :span="12">
            <el-form-item label="小区" prop="areaName">
              <el-select v-model="form.areaName":filter-method="filterMethod" placeholder="请输入小区" filterable allow-create
                         clearable @change="getGroup(form.areaName)" default-first-option >
                <el-option v-for="(item, index) in areaIdOptions" :key="index" :label="item.areaName"
                           :value="item.areaName" :disabled="item.disabled" ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="form.projectType == '2'||form.projectType == '3'" :span="12">
            <el-form-item label="楼宇" prop="groupName">
              <el-select v-model="form.groupName" :style="{width: '100%'}" clearable placeholder="请输入楼宇"
                         @change="getUnit(form.areaName,form.groupName)">
                <el-option v-for="(item, index) in groupIdOptions" :key="index" :disabled="item.disabled"
                           :label="item.groupName" :value="item.groupName"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="form.projectType == '3'" :span="12">
            <el-form-item label="单元" prop="unitName">
              <el-select v-model="form.unitName" :style="{width: '100%'}" clearable placeholder="请输入单元">
                <el-option v-for="(item, index) in unitNameOptions" :key="index" :disabled="item.disabled"
                           :label="item.unitName" :value="item.unitName"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="公示开始" prop="publicityStart">
          <el-date-picker v-model="form.publicityStart" :disabled="form.batchSts==1"
                          :style="{width: '100%'}" placeholder="选择施工前公示开始日期"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="公示结束" prop="publicityEnd">
          <el-date-picker v-model="form.publicityEnd" :disabled="form.batchSts==1"
                          :style="{width: '100%'}" placeholder="选择施工前公示结束日期"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="开始日期" prop="projectStart">
          <el-date-picker v-model="form.projectStart" :disabled="form.batchSts==1"
                          :style="{width: '100%'}" placeholder="选择施工开始日期"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束日期" prop="projectEnd">
          <el-date-picker v-model="form.projectEnd" :disabled="form.batchSts==1"
                          :style="{width: '100%'}" placeholder="选择施工结束日期"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报价日期" prop="priceDate">
          <el-date-picker v-model="form.priceDate" :disabled="form.batchSts==1"
                          :style="{width: '100%'}" placeholder="选择报价截至日期"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
<!--
        <el-button type="primary" @click="resetQuery">重置</el-button>
-->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--    修改框-->
    <el-dialog :title="titleExecute" :visible.sync="openExecute" append-to-body width="600px">
      <el-form ref="form" :model="formExecute" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="维修内容" prop="infoId">
              <el-select v-model="formExecute.infoName" :style="{width: '100%'}" clearable placeholder="请输入维修内容">
                <el-option v-for="(item, index) in projectInfoOptions" :key="index" :disabled="item.disabled"
                           :label="item.infoName" :value="item.infoName">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工程名称" prop="projectName">
              <el-input v-model="formExecute.projectName" maxlength="50" placeholder="请输入工程名称"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工程造价" prop="projectMoney">
              <el-input v-model="formExecute.projectMoney"maxlength="50" placeholder="请输入工程造价"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="施工企业" prop="companyName">
              <el-select v-model="formExecute.companyName" :style="{width: '100%'}" clearable
                         placeholder="请选择施工企业">
                <el-option v-for="(item, index) in companyOptions" :key="index" :disabled="item.disabled"
                           :label="item.companyName" :value="item.companyName"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="formExecute.remark" placeholder="请输入内容" type="textarea"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="公示开始" prop="publicityStart">
          <el-date-picker v-model="formExecute.publicityStart" :disabled="form.batchSts==1"
                          :style="{width: '100%'}" placeholder="选择施工前公示开始日期"
                          size="small"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="公示结束" prop="publicityEnd">
          <el-date-picker v-model="formExecute.publicityEnd" :disabled="form.batchSts==1"
                          :style="{width: '100%'}" placeholder="选择施工前公示结束日期"
                          size="small"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="开始日期" prop="projectStart">
          <el-date-picker v-model="formExecute.projectStart" :disabled="form.batchSts==1"
                          :style="{width: '100%'}" placeholder="选择施工开始日期"
                          size="small"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束日期" prop="projectEnd">
          <el-date-picker v-model="formExecute.projectEnd" :disabled="form.batchSts==1"
                          :style="{width: '100%'}" placeholder="选择施工结束日期"
                          size="small"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="报价日期" prop="priceDate">
          <el-date-picker v-model="formExecute.priceDate" :disabled="form.batchSts==1"
                          :style="{width: '100%'}" placeholder="选择报价截至日期"
                          size="small"
                          type="date"
                          value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitExecuteForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="titleProjectExecute" :visible.sync="openProjectExecute" append-to-body width="500px">
      <el-form ref="form" :model="formProjectExecute" :rules="rules" label-width="80px">
        <el-form-item label="执行时间" prop="executeDate">
          <el-date-picker v-model="formProjectExecute.executeDate"
                          :disabled="form.projectSts==1" :style="{width: '100%'}"
                          clearable
                          placeholder="选择执行时间"
                          type="date" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitProjectExecuteForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看缴费明细记录 -->
    <el-dialog :title="title" :visible.sync="openRepair" width="1000px" append-to-body>
      <el-form :model="queryParams3" :inline="true" v-show="showSearch" label-width="68px">
        <el-table v-loading="loading" :data="repairQueryList">
          <el-table-column label="工程编号" align="center" prop="projectId" />
          <el-table-column label="地址" align="center" prop="doorAddr" width="180"/>
          <el-table-column label="房屋编号" align="center" prop="houseId" />
          <el-table-column label="姓名" align="userName" prop="userName" />
          <el-table-column :formatter="numberFormat" label="当前余额" align="center" prop="balance" />
          <el-table-column :formatter="numberFormat" align="center" label="利息合计" prop="rateMoney"/>
          <el-table-column :formatter="numberFormat" label="扣款金额" align="center" prop="payMoney" />
          <el-table-column :formatter="numberFormat" label="不足金额" align="center" prop="noMoney" />
          <el-table-column label="分摊日期" align="center" prop="executeDate" width="120">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.executeDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="total>0"
          :total="total3"
          :page.sync="queryParams3.pageNum"
          :limit.sync="queryParams3.pageSize"
          @pagination="getRepairList"
        />
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  addProject,
  delProject,
  executeProject,
  getProject,
  getProjectInfoId,
  listProject,
  revokeProject,
  updateProject
} from "@/api/repair/project";
import {
  getCompanyId,getCompanyId1
} from "../../../api/repair/project";
import {listRepairQuery1} from "@/api/repair/repairQuery";
import {getAreaInfo, getAreaInfo1} from "@/api/house/area";
import {getGroupInfo} from "@/api/house/group";
import {getUnitInfo} from "@/api/house/unit";
import {listCostQuery} from "@/api/fund/costQuery";


export default {
  name: "Project",
  dicts: ['REPAIR003', 'COST002', 'COST001', 'REPAIR002'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total3: 0,
      // 维修项目表格数据
      projectList: [],
      repairQueryList: [],
      // 日期范围
      dateRange: [],
      // 弹出层标题
      title: "",
      titleExecute: "",
      titleProjectExecute: "",
      // 是否显示弹出层
      open: false,
      openRepair: false,
      openExecute: false,
      openProjectExecute: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        areaName: null,
        groupName: null,
        unitName: null,
        projectId: null,
        projectSts: null,
        companyId: null,
        companyName: null,
        infoId: null,
        infoName: null,
      },
      // 查询分摊参数
      queryParams3: {
        pageNum: 1,
        pageSize: 10,
        Name: null,
        groupName: null,
        unitName: null,
        doorName: null,
        areaName: null,
        houseId: null,
        projectId: null,
        executeDate: null,
        payMoney: null,
        noMoney: null,
        balance: null,
        startDate:null,
        endDate:null,
      },
      areaIdOptions: [{}],
      groupIdOptions: [{}],
      companyOptions: [{}],
      unitNameOptions: [{}],
      projectInfoOptions: [{}],
      // 表单参数
      form: {},
      formExecute: {},
      formProjectExecute: {},
      // 表单校验
      rules: {
        projectId: [
          {required: true, message: "工程编号不能为空", trigger: "blur"}
        ],
        projectName: [
          {required: true, message: "工程名称不能为空", trigger: "blur"}
        ],
        companyId: [
          {required: true, message: "施工企业不能为空", trigger: "blur"}
        ],
        projectType: [
          {required: true, message: "维修类型不能为空", trigger: "change"}
        ],
        infoId: [
          {required: true, message: "维修内容不能为空", trigger: "blur"}
        ],
        projectMoney: [
          {required: true, message: "工程造价不能为空", trigger: "blur"}
        ],
        trueMoney: [
          {required: true, message: "决算造价不能为空", trigger: "blur"}
        ],
        payMoney: [
          {required: true, message: "拨付金额不能为空", trigger: "blur"}
        ],
        projectSts: [
          {required: true, message: "执行状态不能为空", trigger: "blur"}
        ],
        areaName: [
          {required: true, message: "小区不能为空", trigger: "blur"}
        ],
        unitName: [
          {required: true, message: "单元不能为空", trigger: "blur"}
        ],
        groupName: [
          {required: true, message: "楼宇不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    const id = this.$route.params && this.$route.params.id;
    debugger
    if(id!=null){
      this.getProjectList(id);
    }
    this.getList();
    this.companySelect();
    this.projectInfoSelect();
    this.areaSelect();
  },
  methods: {
/*    handleInput(val) {
      // nextTick确保数据与视图同步
      this.$nextTick(() => {
        // \D:表示非数字，确保输入框只能输入数字
        this.form.projectMoney = val.replace(/\D/g, "");
        this.formExecute.projectMoney = val.replace(/\D/g, "");
        // 得到经过非数字过滤后的值
        const data = val.replace(/\D/g, "");
        // 将值暂存起来
        this.realValue = data;
        // 最关键的步骤：添加千分符
        this.form.projectMoney = data.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
        this.formExecute.projectMoney = data.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
      });
    },*/
    numberFormat (row, column, cellValue) {
      cellValue += ''
      if (!cellValue.includes('.')) cellValue += '.'
      return cellValue.replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) {
        return $1 + ','
      }).replace(/\.$/, '')
    },

    getProjectList(id) {
        this.queryParams.id = id;
        this.getList();
    },
    filterMethod(val){
      this.value=val
      getAreaInfo1(this.value).then(response => {
        this.areaIdOptions = response.rows;
      });
    },
    companyMethod(val){
      this.value=val
      getCompanyId1(this.value).then(response => {
        this.companyOptions = response.rows;
      });
    },
    projectInfoSelect() {
      getProjectInfoId().then(response => {
        this.projectInfoOptions = response.rows;
      });
    },
    companySelect() {
      getCompanyId().then(response => {
        this.companyOptions = response.rows;
      });
    },
    areaSelect() {
      getAreaInfo().then(response => {
        this.areaIdOptions = response.rows;
      });
    },
    getGroup(areaName) {
      getGroupInfo(areaName).then(response => {
        this.groupIdOptions = response.rows;
      });
    },
    getUnit(areaName, groupName) {
      getUnitInfo(areaName, groupName).then(response => {
        this.unitNameOptions = response.rows;
      });
    },
    /** 查询维修项目列表 */
    getList() {
      this.loading = true;
      listProject(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
        this.areaSelect();
      });
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.openExecute = false;
      this.openProjectExecute = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectId: null,
        projectName: null,
        areaName: null,
        groupName: null,
        unitName: null,
        projectaddr: null,
        infoId: null,
        infoName: null,
        projectType: "1",
        projectMoney: null,
        trueMoney: null,
        payMoney: null,
        projectSts: null,
        creater: null,
        createDate: null,
        executer: null,
        executeDate: null,
        publicityStart: null,
        publicityEnd: null,
        projectStart: null,
        projectEnd: null,
        priceDate: null,
        companyId: null,
        companyName: null,
        projectInfoId: null,
        streeter: null,
        streetTel: null,
        communityer: null,
        communityTel: null,
        committeer: null,
        committeeTel: null,
        homer: null,
        homeTel: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.areaSelect();
      this.companySelect();
      this.dateRange = [];
      this.companyMethod();
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.projectId = selection.map(item => item.projectId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.areaSelect();
      this.open = true;
      this.title = "添加维修项目";
    },
    /** 执行按钮操作 */
    submitProjectExecuteForm() {
      executeProject(this.ids, this.formProjectExecute.executeDate).then(response => {
        this.$modal.msgSuccess("执行成功");
        this.openProjectExecute = false;
        this.getList();
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProject(id).then(response => {
        this.formExecute = response.data;
        this.openExecute = true;
        this.titleExecute = "修改";
      });
    },
    repairQuery(row) {
      const projectId = row.projectId;
      this.queryParams3.projectId=projectId
      this.openRepair = true;
      this.getRepairList()
    },
    /** 查询计息明细列表 */
    getRepairList() {
      this.loading = true;
      listRepairQuery1(this.queryParams3).then(response => {
        this.repairQueryList = response.rows;
        this.total3 = response.total;
        this.loading = false;
      });
    },
    /* 撤销*/
    updateRefund(row) {
      const id = row.id || this.ids;
      revokeProject(id).then(response => {
        this.$modal.msgSuccess("该项目以撤销");
        this.getList();
      });

    },
    /** 提交按钮 */
    submitExecuteForm() {
      this.formExecute.projectId = this.form.projectId
      updateProject(this.formExecute).then(response => {
        this.$modal.msgSuccess("修改成功");
        this.openExecute = false;
        this.getList();
      });
    },
    handleProjectExecute(row) {
      this.reset();
      this.openProjectExecute = true;
      this.titleProjectExecute = "执行时间";
    },
    /** 提交按钮 */
    submitForm() {
      debugger
      if(this.form.infoId==null){
        return this.$modal.alertError("维修内容未选取,请清理页面缓存!");
      }
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.areaSelect();
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      debugger
      const ids = row.id || this.ids;
      const projectId = row.projectId || this.projectId;
      this.$modal.confirm('是否确认删除维修项目编号为"' +projectId + '"的数据项？').then(function () {
        return delProject(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },

    //转html打开
    /*downloadOne(row) {
      const ids = row.id || this.ids;
      return downloadOne(ids,"a1");
      window.open('../jsp/repair/camera.html','','width=800,height=600,left=200,location=no,scrollbars=no,titlebar=no');
    },*/

    /** 导出按钮操作 */
    handleExport() {
      this.download('/repair/project/export', {
        ...this.queryParams
      }, `维修项目_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
